﻿<?php include $this->admin_tpl('meta');?>
<title><?php echo $diy_list['name'];?>列表</title>
</head>
<body>	
<div class="page-container" style="padding-bottom:0;">
	<form id="search" class="layui-form">
		<?php
		$input=['search'=>'','field'=>'','totalRow'=>'false'];
		$temp = [];
		$add = [];
		$temp[] = ['type'=>'checkbox','fixed'=>'left'];
		$temp[] = ['field'=>'id','title'=>'ID','width'=>50,'align'=>'center'];
		foreach($field as $k=>$v){
			foreach($v as $key=>$val){
				if($val=='1'&&$key!='id'){
					$field[$k][$key] = true;
				}
				if($val == '0'&&$key!='id'){
					$field[$k][$key] = false;
				}
			}
			if($v['search']){
				if(isset($v['is_switch'])&&$v['is_switch']==true){
					$input['search'] .='<div class="layui-inline ml-5"><select><option value="">是否'.$v['title'].'</option><option value="是">是</option><option value="否">否</option></select></div>';
				}else{
					$input['search'] .='<div class="layui-inline ml-5"><div class="layui-input-inline layui-input-wrap"><input type="input" name="'.$v['field'].'" placeholder="请输入'.$v['title'].'" autocomplete="off" lay-affix="clear" class="layui-input"></div></div>';
				}
			}
			if(isset($v['totalRow'])&&$v['totalRow']==true){
				$input['totalRow'] = true;
			}
			$v['field'] = $k;
			if($v['width']==0){
				unset($field[$k]['width']);
			}else{
				$field[$k]['width'] = intval($v['width']);
			}
			//删除没用用的字段
			unset($field[$k]['search']);
			unset($field[$k]['is_switch']);
			//求和不显示小数点
			if($v['totalRow']==1){
				$field[$k]['totalRowDecimals']=0;
			}
			$temp[]=$field[$k];
			$add[$k]='';
		}
		$add['yzm_csrf_token']=$_SESSION['yzm_csrf_token'];
		$add_time = [
			'sort'=>true,
			'width'=>120,
			'field'=>'add_time',
			'align'=>'center',
			'totalRow'=>false,
			'title'=>'添加时间',
		];
		$modified_time = [
			'sort'=>true,
			'width'=>120,
			'field'=>'modified_time',
			'align'=>'center',
			'totalRow'=>false,
			'title'=>'修改时间',
		];
		$temp[]=$add_time;
		$temp[]=$modified_time;
		$input['field'] = json_encode($temp);
		echo $input['search'];
		?>
		<input type="hidden" value="" name="field">
		<input type="hidden" value="" name="order">
		<input type="hidden" value="<?php echo $type;?>" name="type">
		<input type="hidden" value="0" name="download">
		<a class="btn btn-success radius" href="javascript:void(0)" id="btn_search"><i class="yzm-iconfont yzm-iconsousuo"></i> 搜索</a>
		<button class="btn btn-primary radius" id="btn_reset" type="reset"><i class="yzm-iconfont yzm-iconshuaxin"></i> 重置</button>
		<a class="btn btn-success radius" href="<?php echo U('diy_list');?>" id="btn_search"><i class="yzm-iconfont yzm-iconneirong"></i> 选择表格</a>
	</form>
	
	<table id="table" class="mt-20" lay-filter="table"></table>
</div>

<script type="text/html" id="tool_temp">
	<a href="javascript:;" onclick="add()" class="btn btn-primary radius"><i class="yzm-iconfont yzm-icontianjia"></i> 添加记录</a>
	<a href="javascript:;" id="btn_del" class="btn btn-danger radius"><i class="yzm-iconfont yzm-iconshanchu2"></i> 批量删除</a>
</script>
<script type="text/html" id="op_temp">
	<a class="layui-btn layui-btn-yzm layui-btn-xs" onclick="yzm_open('添加店铺','<?php echo U('shop_list',['type'=>'add']);?>?id={{= d.id}}','800','700')" lay-event="detail" style="text-decoration:none;">编辑字段</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete" style="text-decoration:none;">删除</a>
</script>
<script type="text/html" id="jst_id_temp">
  <button class="layui-btn layui-btn-primary dropdown-jst" style="height:28px;width:90px;padding:0 10px;">
    <span>{{= d.jst_name}}</span>
    <i class="layui-icon layui-icon-down layui-font-12" style="vertical-align: center;"></i>
  </button>
</script>

<?php include $this->admin_tpl('footer');?>
<script type="text/javascript" src="<?php echo STATIC_URL;?>plugin/layui/layui.js"></script>

<script>
var db = 'hr_diy_content';
var url = '/admin/hr_diy/';
layui.use(function(){ //亦可加载特定模块：layui.use(['layer', 'laydate', function(){
	table = layui.table; //表格
	util = layui.util; //工具集
	dropdown = layui.dropdown; //下拉菜单
	form = layui.form;
	//执行一个 table 实例
	option = {
		elem: '#table',
		id:'table',
		height: 'full-80',
		method:'post',
		limit:30,
		limits:[30,60,90],
		url:'<?php echo U('diy_list',['type'=>$type]);?>',
		where: $('#search').serializeJson(),
		title: '<?php echo $diy_list['name'];?>',
		autoSort: false,
		totalRow: <?php echo $input['totalRow'];?>, // 开启合计行
		page: {theme:'#409eff',groups:3,hash:true}, //开启分页
		toolbar: '#tool_temp', //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
		cols: [<?php echo $input['field'];?>],
		done:function(res,curr,count){
			var options = this;
			public_table(db,url);
		}
	};
	table.render(option);
	init_table(db,url);
	
})
function add(){
	$.ajax({
		type: 'POST',
		url: '<?php echo U('diy_list',['type'=>$type,'action'=>'add']);?>', 
		data: <?php echo json_encode($add);?>,
		dataType: "json", 
		success: function (msg) {
			if(msg.status == 1){
				table.reload('table');
			}else{
				layer.msg(msg.message, {icon:2});
			}
		}
	})		
}
</script>
</body>
</html>